<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="120px">
      <el-form-item label="联系方式" prop="tel">
        <el-input v-model="queryParams.tel" placeholder="请输入联系方式" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="姓名" prop="name">
        <el-input v-model="queryParams.name" placeholder="请输入姓名" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <!-- <el-form-item label="身份证号" prop="identityCard">
        <el-input v-model="queryParams.identityCard" placeholder="请输入身份证号" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="企业名称" prop="companyName">
        <el-input v-model="queryParams.companyName" placeholder="请输入企业名称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="法人姓名" prop="legalPerson">
        <el-input v-model="queryParams.legalPerson" placeholder="请输入法人姓名" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="公司联系方式" prop="companyTel">
        <el-input v-model="queryParams.companyTel" placeholder="请输入公司联系方式" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="认证结果" prop="authResult">
        <el-input v-model="queryParams.authResult" placeholder="请输入认证结果" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="认证状态" prop="authState">
        <el-input v-model="queryParams.authState" placeholder="请输入认证状态" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="审核人ID" prop="auditPersonId">
        <el-input v-model="queryParams.auditPersonId" placeholder="请输入审核人ID" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="审核人姓名" prop="auditPerson">
        <el-input v-model="queryParams.auditPerson" placeholder="请输入审核人姓名" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="微信ID" prop="wxId">
        <el-input v-model="queryParams.wxId" placeholder="请输入微信ID" clearable @keyup.enter.native="handleQuery" />
      </el-form-item> -->
      <el-form-item label="用户昵称" prop="wxName">
        <el-input v-model="queryParams.wxName" placeholder="请输入用户昵称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <!-- <el-form-item label="开户行" prop="bankName">
        <el-input v-model="queryParams.bankName" placeholder="请输入开户行" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="户名" prop="bankAccount">
        <el-input v-model="queryParams.bankAccount" placeholder="请输入户名" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="账号" prop="bankAccountNo">
        <el-input v-model="queryParams.bankAccountNo" placeholder="请输入账号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item> -->
      <el-form-item label="最近活动时间" prop="lastLoginTime" width="120px">
        <el-date-picker clearable v-model="queryParams.lastLoginTime" type="date" value-format="yyyy-MM-dd"
          placeholder="请选择最近活动时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="创建时间">
        <el-date-picker v-model="dateRange" style="width: 240px" value-format="yyyy-MM-dd" type="daterange"
          range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <!-- <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
          v-hasPermi="['system:customer:add']">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate"
          v-hasPermi="['system:customer:edit']">修改</el-button>
      </el-col> -->
      <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
          v-hasPermi="['system:customer:remove']">删除</el-button>
      </el-col>
      <!-- <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
          v-hasPermi="['system:customer:export']">导出</el-button>
      </el-col> -->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="customerList" @selection-change="handleSelectionChange"
      @row-dblclick="dbclick">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="ID" align="center" prop="id" />
      <el-table-column label="用户昵称" align="center" prop="wxName" />
      <el-table-column label="认证类型" align="center" prop="authType" />
      <el-table-column label="联系方式" align="center" prop="tel" />
      <el-table-column label="姓名" align="center" prop="name" />
      <el-table-column label="认证状态" align="center" prop="authState" />
      <el-table-column label="关联订单数" align="center" prop="authState" width="100" />
      <el-table-column label="关联账单数" align="center" prop="authState" width="100" />
      <el-table-column label="发票信息" align="center" prop="authState" />
      <!-- <el-table-column label="性别" align="center" prop="sex" />
      <el-table-column label="身份证号" align="center" prop="identityCard" />
      <el-table-column label="身份证正面url" align="center" prop="cardFrontImg" />
      <el-table-column label="身份证反面url" align="center" prop="cardBackImg" />
      <el-table-column label="企业名称" align="center" prop="companyName" />
      <el-table-column label="统一社会信用编码" align="center" prop="businessLicense" />
      <el-table-column label="法人姓名" align="center" prop="legalPerson" />
      <el-table-column label="公司联系方式" align="center" prop="companyTel" />
      <el-table-column label="公司营业执照" align="center" prop="licenseImg" />
      <el-table-column label="认证结果" align="center" prop="authResult" />

      <el-table-column label="审核人ID" align="center" prop="auditPersonId" />
      <el-table-column label="审核人姓名" align="center" prop="auditPerson" />
      <el-table-column label="微信ID" align="center" prop="wxId" /> -->
      <!-- <el-table-column label="头像URL" align="center" prop="headImgUrl" /> -->

      <!-- <el-table-column label="开户行" align="center" prop="bankName" />
      <el-table-column label="户名" align="center" prop="bankAccount" />
      <el-table-column label="账号" align="center" prop="bankAccountNo" /> -->
      <el-table-column label="最近活动时间" align="center" prop="lastLoginTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.lastLoginTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="创建时间" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <!-- <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
            v-hasPermi="['system:customer:edit']">修改</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
            v-hasPermi="['system:customer:remove']">删除</el-button>
        </template>
      </el-table-column> -->
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 添加或修改用户信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="联系方式" prop="tel">
          <el-input v-model="form.tel" placeholder="请输入联系方式" />
        </el-form-item>
        <el-form-item label="姓名" prop="name">
          <el-input v-model="form.name" placeholder="请输入姓名" />
        </el-form-item>
        <el-form-item label="身份证号" prop="identityCard">
          <el-input v-model="form.identityCard" placeholder="请输入身份证号" />
        </el-form-item>
        <el-form-item label="身份证正面url" prop="cardFrontImg">
          <el-input v-model="form.cardFrontImg" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="身份证反面url" prop="cardBackImg">
          <el-input v-model="form.cardBackImg" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="企业名称" prop="companyName">
          <el-input v-model="form.companyName" placeholder="请输入企业名称" />
        </el-form-item>
        <el-form-item label="统一社会信用编码" prop="businessLicense">
          <el-input v-model="form.businessLicense" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="法人姓名" prop="legalPerson">
          <el-input v-model="form.legalPerson" placeholder="请输入法人姓名" />
        </el-form-item>
        <el-form-item label="公司联系方式" prop="companyTel">
          <el-input v-model="form.companyTel" placeholder="请输入公司联系方式" />
        </el-form-item>
        <el-form-item label="公司营业执照" prop="licenseImg">
          <el-input v-model="form.licenseImg" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="认证结果" prop="authResult">
          <el-input v-model="form.authResult" placeholder="请输入认证结果" />
        </el-form-item>
        <el-form-item label="认证状态" prop="authState">
          <el-input v-model="form.authState" placeholder="请输入认证状态" />
        </el-form-item>
        <el-form-item label="审核人ID" prop="auditPersonId">
          <el-input v-model="form.auditPersonId" placeholder="请输入审核人ID" />
        </el-form-item>
        <el-form-item label="审核人姓名" prop="auditPerson">
          <el-input v-model="form.auditPerson" placeholder="请输入审核人姓名" />
        </el-form-item>
        <el-form-item label="微信ID" prop="wxId">
          <el-input v-model="form.wxId" placeholder="请输入微信ID" />
        </el-form-item>
        <el-form-item label="头像URL" prop="headImgUrl">
          <el-input v-model="form.headImgUrl" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="用户昵称" prop="wxName">
          <el-input v-model="form.wxName" placeholder="请输入用户昵称" />
        </el-form-item>
        <el-form-item label="开户行" prop="bankName">
          <el-input v-model="form.bankName" placeholder="请输入开户行" />
        </el-form-item>
        <el-form-item label="户名" prop="bankAccount">
          <el-input v-model="form.bankAccount" placeholder="请输入户名" />
        </el-form-item>
        <el-form-item label="账号" prop="bankAccountNo">
          <el-input v-model="form.bankAccountNo" placeholder="请输入账号" />
        </el-form-item>
        <el-form-item label="最近活动时间" prop="lastLoginTime">
          <el-date-picker clearable v-model="form.lastLoginTime" type="date" value-format="yyyy-MM-dd"
            placeholder="请选择最近活动时间">
          </el-date-picker>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 用户详情 -->
    <el-dialog title="用户详情" :visible.sync="detailOpen" width="1200px" height="1000px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-row :gutter="20">
          <el-col :span="6">
            <div class="grid-content bg-purple-dark">
              <el-form-item label="头像" prop="tel">
                <el-avatar :size="100" :src="form.headImgUrl"></el-avatar>
              </el-form-item>
              <el-form-item label="联系方式" prop="tel">
                <el-input v-model="form.tel" placeholder="请输入联系方式" />
              </el-form-item>
              <el-form-item label="姓名" prop="name">
                <el-input v-model="form.name" placeholder="请输入姓名" />
              </el-form-item>
            </div>
          </el-col>
          <el-col :span="18">
            <el-row>
              <el-card class="box-card">
                <div slot="header" class="clearfix">
                  <span>用户信息</span>
                </div>
                <!-- <el-col :span="12">

                  <div class="grid-content bg-purple-dark"><el-form-item label="联系方式" prop="tel">
                      <el-input v-model="form.tel" placeholder="请输入联系方式" readonly />
                    </el-form-item>
                    <el-form-item label="姓名" prop="name">
                      <el-input v-model="form.name" placeholder="请输入姓名" />
                    </el-form-item>
                    <el-form-item label="身份证号" prop="identityCard">
                      <el-input v-model="form.identityCard" placeholder="请输入身份证号" />
                    </el-form-item>
                    <el-form-item label="身份证正面" prop="cardFrontImg">
                      <el-input v-model="form.cardFrontImg" type="textarea" placeholder="请输入内容" />
                    </el-form-item>
                    <el-form-item label="身份证反面" prop="cardBackImg">
                      <el-input v-model="form.cardBackImg" type="textarea" placeholder="请输入内容" />
                    </el-form-item>
                  </div>


                </el-col> -->
                <el-col :span="23">
                  <div class="text item">
                    <el-form-item label="企业名称" prop="companyName">
                      <el-input v-model="form.companyName" placeholder="请输入企业名称" />
                    </el-form-item>
                    <el-form-item label="统一社会信用编码" prop="businessLicense">
                      <el-input v-model="form.businessLicense" type="textarea" placeholder="请输入内容" />
                    </el-form-item>
                    <el-form-item label="法人姓名" prop="legalPerson">
                      <el-input v-model="form.legalPerson" placeholder="请输入法人姓名" />
                    </el-form-item>
                    <el-form-item label="公司联系方式" prop="companyTel">
                      <el-input v-model="form.companyTel" placeholder="请输入公司联系方式" />
                    </el-form-item>
                    <el-form-item label="公司营业执照" prop="licenseImg">
                      <el-input v-model="form.licenseImg" type="textarea" placeholder="请输入内容" />
                    </el-form-item>
                  </div>
                  <!-- <div class="grid-content bg-purple-dark">
                 
                </div> -->
                </el-col>
              </el-card>
            </el-row>

            <el-row><el-col :span="24">
                <el-card class="box-card">
                  <div slot="header" class="clearfix">
                    <span>发票抬头</span>
                  </div>
                  <div class="grid-content bg-purple-dark">
                    <el-table v-loading="loading" :data="headList">
                      <el-table-column label="抬头类型" align="center" prop="headType" />
                      <el-table-column label="发票样式" align="center" prop="style" />
                      <el-table-column label="抬头" align="center" prop="headInfo" />
                      <el-table-column label="税 号" align="center" prop="taxNo" />
                      <el-table-column label="邮箱" align="center" prop="email" />
                      <el-table-column label="注册地址" align="center" prop="rejectAddress" />
                      <el-table-column label="注册手机" align="center" prop="rejectTel" />
                      <el-table-column label="开户银行" align="center" prop="companyBankName" />
                      <el-table-column label="银行账号" align="center" prop="companyBankAccount" />
                      <el-table-column label="地区" align="center" prop="companyArea" />
                      <el-table-column label="详细地址" align="center" prop="companyAddress" />
                      <el-table-column label="记录ID" align="center" prop="id" />
                      <el-table-column label="客户ID" align="center" prop="customerId" />
                      <el-table-column label="客户姓名" align="center" prop="customerName" />
                      <el-table-column label="发票类型" align="center" prop="invcoieType" />
                      <el-table-column label="省市区" align="center" prop="area" />
                      <el-table-column label="详细地址" align="center" prop="address" />
                      <el-table-column label="是否默认0：不是，1：默认" align="center" prop="defaultFlag" />

                    </el-table>

                  </div>
                </el-card>
              </el-col></el-row>
          </el-col>
        </el-row>
      </el-form>
    </el-dialog>


  </div>
</template>

<script>
import { listCustomer, getCustomer, delCustomer, addCustomer, updateCustomer } from "@/api/system/customer";
import { listHead } from "@/api/system/head";

export default {
  name: "Customer",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 用户信息表格数据
      customerList: [],

      // 日期范围
      dateRange: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,

      //是否显示详情页
      detailOpen: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        authType: null,
        tel: null,
        name: null,
        identityCard: null,
        cardFrontImg: null,
        cardBackImg: null,
        companyName: null,
        businessLicense: null,
        legalPerson: null,
        companyTel: null,
        licenseImg: null,
        authResult: null,
        authState: null,
        auditPersonId: null,
        auditPerson: null,
        wxId: null,
        headImgUrl: null,
        bankName: null,
        bankAccount: null,
        bankAccountNo: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },
      //发票抬头数据
      headList: []
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询用户信息列表 */
    getList() {
      this.loading = true;

      listCustomer(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
        this.customerList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        authType: null,
        tel: null,
        name: null,
        identityCard: null,
        cardFrontImg: null,
        cardBackImg: null,
        companyName: null,
        businessLicense: null,
        legalPerson: null,
        companyTel: null,
        licenseImg: null,
        authResult: null,
        authState: null,
        auditPersonId: null,
        auditPerson: null,
        wxId: null,
        headImgUrl: null,
        bankName: null,
        bankAccount: null,
        bankAccountNo: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加用户信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getCustomer(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改用户信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateCustomer(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addCustomer(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除用户信息编号为"' + ids + '"的数据项？').then(function () {
        return delCustomer(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/customer/export', {
        ...this.queryParams
      }, `customer_${new Date().getTime()}.xlsx`)
    },
    dbclick(row) {
      console.log(row);
      this.detailOpen = true;
      const id = row.id || this.ids
      getCustomer(id).then(response => {
        this.form = response.data;
      });

      listHead({ "customerId": id }).then(response => {
        this.headList = response.rows;
      });
    }
  }
};
</script>
<style>
.row-bg {
  padding: 10px 0;
  background-color: #f9fafc;
}
</style>